<?php
/**
 * Created by novebeta.
 * Date: 11/16/12
 * Time: 1:09 PM
 */
class FrontEndController extends CController
{
    public $layout = '//layouts/main';
    public $slideshow = 0;
    public $autoplay = 0;
    public $start_slide = 0;
    public $height = 'height: 768px;';
    public $image = "";
    public $imageket = "";
    public $nav = '';
    public $menu = array();
    public $judul_hal = '';
    public $showEvent = false;
    public $label_menu_active = '';

//    public function __construct($id, $module = null)
//    {
//        parent::__construct($id, $module);
//        if (isset($_POST['language'])) {
//            $lang = $_POST['language'];
//            $MultilangReturnUrl = $_POST[$lang];
//            $this->redirect($MultilangReturnUrl);
//        }
//        if (isset($_GET['language'])) {
//            Yii::app()->language = $_GET['language'];
//            Yii::app()->user->setState('language', $_GET['language']);
//            $cookie = new CHttpCookie('language', $_GET['language']);
//            $cookie->expire = time() + (60 * 60 * 24 * 365); // (1 year)
//            Yii::app()->request->cookies['language'] = $cookie;
//        } else if (Yii::app()->user->hasState('language')) Yii::app()->language =
//            Yii::app()->user->getState('language'); else if (isset(Yii::app()->request->cookies['language']))
//            Yii::app()->language = Yii::app()->request->cookies['language']->value;
//    }

    public function render($view, $data = null, $return = false)
    {
        $meta = param('meta');
        cs()->registerMetaTag("text/html; charset=ISO-8859-1",null,"Content-Type");
        cs()->registerMetaTag("no-cache",null,"pragma");
        cs()->registerMetaTag("no-cache",null,"cache-control");
        cs()->registerMetaTag($meta['desc'],'Description');
        cs()->registerMetaTag($meta['Keywords'],'Keywords');
        cs()->registerMetaTag($meta['Author'],'Author');
        cs()->registerMetaTag("all",'robots');
        cs()->registerMetaTag("index, follow",'robots');
        cs()->registerLinkTag("shortcut icon","image/x-icon",bu()."/img/icon.ico");
        //$theme = app()->theme->name;
        //if (app()->theme->name == 'erictheme')         {
       
            //theme sf
          //cs()->registerCssFile(bu() . '/css/sf_style.css');  
        //}else
       // {
         //  cs()->registerCssFile(bu() . '/css/style.css'); 
      //  }
        
        //cs()->registerCssFile(bu() . '/css/menu.css');
        cs()->registerCssFile(bu() . '/plugins/slimbox2/slimbox2.css');
        cs()->registerCoreScript('jquery');
        cs()->registerScriptFile(bu() . '/plugins/slimbox2/slimbox2.js');
        
        //$this->layout = "main";
        
        
//        $actionId = "index";
//        if(isset($this->action))
//            $actionId = $this->action->id;
//        $controlId = $this->id;
//        if ($controlId == "site" && $actionId == "index") {
//            $this->layout = "//layouts/main";
//        } else {
//            $this->image = "{image : '" . bu() . "/img/8.jpg', title : 'c', thumb : '" . bu() . "/img/8.jpg', url : ''}";
//            if (isset($_GET['slug'])) {
//                $model = Page::model()->find('slug_id=:slug_id or slug_en=:slug_en',
//                    array('slug_id' => $_GET['slug'], 'slug_en' => $_GET['slug']));
//            } else {
//                if (isset($this->action)) $actionId = $this->action->id;
//                $model = Page::model()->find('file_include=:file', array('file' => $controlId . "/" . $actionId));
//                if ($model == null) {
//                    $model = Page::model()->find('file_include like :file', array('file' => $controlId . "/%"));
//                }
//            }
//            if ($model != null) {
//                $this->menu = CmsU::frontMenu($model->halaman_id);
//                if ($model->top_halaman != 1) {
//                    foreach (CmsU::frontMenu($model->top_halaman) as $menu) {
//                        $this->menu[] = $menu;
//                    }
//                }
//            }
//            if (count($this->menu) == 0 && !$this->showEvent) $this->layout = "//layouts/column1"; else
//                $this->layout = "//layouts/column2";
//        }
//        if ($controlId == "site" && $actionId == "index")
//            $this->pageTitle = app()->name;
//        $this->pageTitle = app()->name . " - " .$this->pageTitle;
        parent::render($view, $data, $return);
    }

    public function createMultilanguageReturnUrl($lang = 'en')
    {
        if (count($_GET) > 0) {
            $arr = $_GET;
            $arr['language'] = $lang;
            if (isset($arr['slug'])) {
                $model = $this->loadModelSlug($arr['slug']);
                $arr['slug'] = $lang == "id" ? $model->slug_id : $model->slug_en;
                //$this->menu = CmsU::frontMenu($model->halaman_id);
            }
        } else
            $arr = array('language' => $lang);
        return $this->createUrl('', $arr);
    }
    

    
    
    
    
}
